package mm.view;

import java.io.Serializable;
import java.util.Locale;
import java.util.Map;

import mm.util.Constants;

public class User implements Serializable {

	private static final long serialVersionUID = 1L;

	private String nick;
	
	private Byte languageCode;
	private Locale requestLocale;
	private boolean signedIn;
	private Serializable id;

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public Byte getLanguageCode() {
		return languageCode;
	}

	public void setLanguageCode(Byte languageCode) {
		this.languageCode = languageCode;
	}

	public Locale getLocale() {
		return Constants.LOCALES.getBar(this.languageCode);
	}

	public void setLocale(Locale locale) {
		this.languageCode = Constants.LOCALES.getFoo(locale);
	}

	public Locale getRequestLocale() {
		return requestLocale;
	}

	public void setRequestLocale(Locale requestLocale) {
		this.requestLocale = requestLocale;
	}

	public boolean isSignedIn() {
		return signedIn;
	}

	public void setSignedIn(boolean signedIn) {
		this.signedIn = signedIn;
	}

	public Serializable getId() {
		return id;
	}

	public void setId(Serializable id) {
		this.id = id;
	}

	public boolean isAbleToCreateArticle() {
		return this.isSignedIn();
	}

	public boolean canEdit(Map article) {
		return canDelete(article);
	}

	public boolean canDelete(Map article) {
		return this.isSignedIn()&&!(Boolean)article.get("is_deleted");
	}

	public boolean canRestore(Map article) {
		return this.isSignedIn()&&(Boolean)article.get("is_deleted");
	}

	public void in(Map user) {
		this.setId((Serializable)user.get("id"));
		this.setSignedIn(true);
		this.setNick((String) user.get("nick"));
	}

	public void out() {
		this.setId(null);
		this.setSignedIn(false);
		this.setNick(null);
	}

}
